package com.cdgeekcamp.redas.lib.core.util;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.regex.Pattern;

public class EduLevelMap {
    public static int getLevel(String str){
        Map<String, Integer> eduLevelMap = new HashMap<>();
        eduLevelMap.put(".*不限.*", 0);
        eduLevelMap.put(".*初中.*", 1);
        eduLevelMap.put(".*高中.*", 2);
        eduLevelMap.put(".*中专.*", 3);
        eduLevelMap.put(".*大专.*", 4);
        eduLevelMap.put(".*本科.*", 5);
        eduLevelMap.put(".*硕士.*", 6);
        eduLevelMap.put(".*博士.*", 7);

        Integer result = 0;

        Iterator it = eduLevelMap.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry item = (Map.Entry)it.next();

            boolean isMatch = Pattern.matches((String) item.getKey(), str);
            if (isMatch){
                result = (Integer) item.getValue();
            }
            it.remove();
        }

        return  result;

    }

    public static String getLevel(int str) {
        Map<Integer, String> eduLevelMap = new HashMap<>();
        eduLevelMap.put(0, "不限");
        eduLevelMap.put(1, "初中");
        eduLevelMap.put(2, "高中");
        eduLevelMap.put(3, "中专");
        eduLevelMap.put(4, "大专");
        eduLevelMap.put(5, "本科");
        eduLevelMap.put(6, "硕士");
        eduLevelMap.put(7, "博士");

        String result = "不限";

        Iterator it = eduLevelMap.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry item = (Map.Entry)it.next();
            int key = (int) item.getKey();
            if (key == str){
                result = (String) item.getValue();
            }
            it.remove();
        }

        return result;
    }

}
